package main;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import crm.base.model.Page;
import crm.system.entity.Agent;
import crm.system.mapper.AgentMapper;
import crm.system.mapper.RoleMapper;
import crm.system.service.AgentService;


public class Main {

	public static void main(String[] args) {
		
		ApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext.xml");
		
		AgentMapper agentMapper = ctx.getBean(AgentMapper.class);
		RoleMapper roleMapper = ctx.getBean(RoleMapper.class);
		AgentService agentService = ctx.getBean(AgentService.class);
		
//		Agent agent = agentMapper.getAgentAuthoritiesByUserName("admin");
//		System.out.println(agent);
//		System.out.println(agent.getRole());
//		for (Authority authority : agent.getRole().getAuthorities()) {
//			System.out.println(authority);
//		}
		
//		long t1 = System.currentTimeMillis();
//		List<Role> roles = roleMapper.getRoles();
//		long t2 = System.currentTimeMillis();
//		System.out.println(t2- t1);
//		System.out.println(roles.size());
//		for (Role role : roles) {
//			System.out.println(role.getAuthorities());
		
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userName", "g00%");
		Page page = new Page(5);
		page.setPageNo(1);
//		
//		page = agentService.getAgentPageList(params, page);
//		System.out.println(page.getTotalCount());
//		for (Object agent : page.getResult()) {
//			System.out.println((Agent) agent);
//		}

		List<Agent> agents = agentMapper.getAgentList(params, page);
		for (Object agent : agents) {
			System.out.println((Agent) agent);
		}
	}

}
